import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Query,
  Res,
  Req
} from '@nestjs/common';
import { StudentService } from './student.service';
import { 
  CreateStudentDto,
  UpdateStudentDto,
  QueryStudentDto,
  DeleteStudentDto
} from './dto/student.dto';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { Response,Request } from 'express';
import { RequirePermission } from 'src/decorator/reuqire-permission';

@ApiTags('学生表管理')
@Controller('student')
@ApiBearerAuth()
export class StudentController {
  constructor(private readonly studentService: StudentService) {}

  @Post()
  @ApiOperation({ summary: '创建学生表' })
  @RequirePermission("system:student:add")
  create(@Body() createStudentDto: CreateStudentDto,@Req() req:Request) {
    return this.studentService.create(createStudentDto,req);
  }

  @Get()
  @ApiOperation({ summary: '学生表列表' })
  @RequirePermission("system:student:list")
  findAll(@Query() query: QueryStudentDto) {
    return this.studentService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '学生表详情' })
  findOne(@Param('id') id: string) {
    return this.studentService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '修改学生表' })
  @RequirePermission("system:student:edit")
  update(@Param('id') id: string, @Body() updateStudentDto: UpdateStudentDto,@Req() req:Request) {
    return this.studentService.update(+id, updateStudentDto,req);
  }

  @Post('delete')
  @ApiOperation({ summary: '删除学生表' })
  @RequirePermission("system:student:remove")
  remove(@Body() dto: DeleteStudentDto) {
    return this.studentService.remove(dto.ids);
  }

  @Post('excel')
  @ApiOperation({ summary: '导出学生表' })
  @RequirePermission("system:student:export")
  exportToExcel(@Res() res: Response) {
    return this.studentService.exportToExcel(res);
  }
}
